package com.lottery.ruok.lottrey.chat.model.text;

import android.text.SpannableStringBuilder;
import android.view.View;

import com.lottery.ruok.lottrey.chat.event.manager.SecretManager;

import io.rong.imkit.model.ProviderTag;
import io.rong.imkit.model.UIMessage;
import io.rong.imkit.widget.provider.TextMessageItemProvider;
import io.rong.message.TextMessage;

/**
 * 重写融云文本viewprovider （主要是为了加解密）
 */
@ProviderTag(
        messageContent = TextMessage.class,
        showReadState = true
)
public class AppTextMessageItemProvider extends TextMessageItemProvider {
    @Override
    public void bindView(final View v, int position, TextMessage content, final UIMessage data) {
        try {
            //解密
            data.setTextMessageContent(new SpannableStringBuilder(SecretManager.getInstance().decode(data.getTextMessageContent().toString())));
        } catch (Exception e) {
            e.printStackTrace();
        }
        super.bindView(v, position, content, data);
        try {
            //加密
            data.setTextMessageContent(new SpannableStringBuilder(SecretManager.getInstance().encode(data.getTextMessageContent().toString())));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
